#!/bin/bash
set -e

while getopts  ":s:w:c:p:g:a:" opts
do
	case  $opts  in
	s)
		sample_name=$OPTARG
		;;
	w)
		window=$OPTARG
		;;
	c)
		c_const=$OPTARG
		;;
	g)
        ref_genome=$OPTARG
        ;;
	p)
        out_prefix=$OPTARG
        ;;
	a)
        seq_method=$OPTARG
        ;;
	\?)
		echo `basename $0` "[-a seq_method] [-s sample_name] [-w window_size] [-g ref_genome_file] <r1.fq> <r2.fq>"
		exit 1
		;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-a seq_method] [-s sample_name] [-w window_size] [-g ref_genome_file] <r1.fq> <r2.fq>'
	exit 1
fi

makedir=true

#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------


if [ -z $out_prefix ]; then
	out_prefix=1
fi

if [ -z "$window" ]; then
	window=200000
fi

if [ -z "$seq_method" ]; then
	seq_method=malbac
fi


if
echo $1 |perl -n -e 'if(/^\//){exit 0;}else{exit 2;}' 2>>$log
then
	if test "$seq_method" = "malbac"; then
	cutadp_malbac.sh $1 $2
	else
	cutadp.sh $1 $2
	fi
else
	if test "$seq_method" = "malbac"; then
	cutadp_malbac.sh $1 $2
	else
	cutadp.sh $1 $2
	fi
fi

align2bam.sh -s $sample_name 1.1.cut.fastq 1.2.cut.fastq

hmmcopy0909.sh -w $window 1.sort.bam

summ_sc_gatk.sh 1.sort.bam $data_path/intervals/1/cnv_sc/b37.rand.site.bed

